﻿using Mad.Core.DomainServices;
using Mad.Core.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mad.Infrastructure.ApplicationServices
{
    public class AppConfig : IAppConfig
    {
        public string DataSourceConnection
        {
            get {
                var key = ConfigurationManager.ConnectionStrings["DataSourceConnection"];
                if (key != null)
                {
                    return key.ConnectionString;
                }

                return string.Empty;
            }
        }


        public string DestinationConnection
        {
            get
            {
                var key = ConfigurationManager.ConnectionStrings["DestinationConnection"];
                if (key != null)
                {
                    return key.ConnectionString;
                }

                return string.Empty;
            }
        }

        public SqlConnectionStringBuilder GetConnectionStringBuilder(ProviderInfo provider)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder.DataSource = provider.Server;
            builder.InitialCatalog = provider.InitialCatalog;
            if (string.IsNullOrEmpty(provider.UserID) && string.IsNullOrEmpty(provider.Password))
            {
                builder.IntegratedSecurity = true;
            }
            else
            {
                builder.UserID = provider.UserID;
                builder.Password = provider.Password;
            }

            return builder;
        }
    }
}
